package com.woupla.account;

import java.io.Serializable;
import java.util.List;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceException;

import org.jboss.solder.logging.Category;
import org.jboss.solder.logging.Logger;

import com.woupla.model.User;


/**
 * Session Bean implementation class UserEJB
 */

@Stateless
public class UserEJB implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 6268553306817632324L;

	@Inject
        @Category("woupla")
	private Logger log;

	@Inject
	private EntityManager em;

	/**
	 * Default constructor.
	 */
	public UserEJB() {
		// TODO Auto-generated constructor stub
	}

	/* (non-Javadoc)
	 * @see com.service.UserInterface#getAllUsers()
	 */
	public List<User> getAllUsers() {
		@SuppressWarnings("unchecked")
		List<User> users = em.createNamedQuery("findAllCustomers").getResultList();
		return users;
	}

	/* (non-Javadoc)
	 * @see com.service.UserInterface#saveUser(com.model.User)
	 */
	public void saveUser(User user) throws PersistenceException {
		log.info("Registering " + user.getLastName());
		em.persist(user);
	}
	public void updateUser(User user){
		em.merge(user);
	}
	/* (non-Javadoc)
	 * @see com.service.UserInterface#findUser(com.model.User)
	 */
	public void findUser(User userTemp){
		User user = (User) em.createQuery("Select c from User c ").getSingleResult();
		log.info(user.getFirtName() + " " + user.getLastName());
	}

}
